package besta.moon.sql.expression.function.string;

import besta.moon.sql.expression.function.FunctionReturnInt;
import besta.moon.sql.parser.SQLTokenizer;

public final class FunctionLength extends FunctionReturnInt {

    @Override
    public final int getFunction() {
        return SQLTokenizer.LENGTH;
    }

    @Override
    public final int getInt() throws Exception {
        String str = param1.getString();
        if (str == null) {
            return 0;
        }
        int length = str.length();
        while (length >= 0 && str.charAt(length - 1) == ' ') {
            length--;
        }
        return length;
    }
}
